<?php
declare(strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\service\MessageService;
use think\facade\Log;

class RetryFailedMessages extends Command
{
    protected function configure()
    {
        $this->setName('retry:failed_messages')
            ->setDescription('Retry failed messages');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            $output->writeln('Start retrying failed messages...');
            
            $messageService = new MessageService();
            $result = $messageService->retryFailedMessages();
            
            $output->writeln($result ? 'Retry completed successfully!' : 'Retry completed with errors!');
            
        } catch (\Exception $e) {
            Log::error('Retry failed messages failed: ' . $e->getMessage());
            $output->writeln('Retry failed messages failed: ' . $e->getMessage());
        }
    }
} 